package skeleton;

import java.util.Scanner;

public class Main {

   static{
        Logger.Message("Logger Created");
        Logger.Message("Prompter Created");
        Logger.Message("ErrorController Created");
        Logger.Message("NetworkController Created");
        Logger.Message("SimulationController Created");            
        Logger.Message("NetworkLoaderController Created");
    }
    public static void main(String[] args) {
        try{
            System.out.println();
            System.out.println("\t\t-=| DigiJoe |=-");
            System.out.println("\t\t    by Joez");
            System.out.println("\t\t   -Skeleton-\t");
            System.out.println();
            
            int answer = Prompter.Switch( new String[] {
                "Initialize --> Statikus Classok letrehozasa, epitoelemek letrehozasa, Vezetekek letrehozasa",
                "Szimulacio leptetese --> Kapulogikak, Generatorok leptetese, Vezetekek frissitese",
                "Szimulacio resetelese --> Vezetekek resetelese, Generatorok resetelese",
                "Kapcsolo atkapcsolasa --> Vezetekek frissitese",
                "Visszacsatolas"
            });
            switch (answer) {
                    case 0:
                        System.out.println("Initialize");
                        System.out.println("----------");
                        
                        NetworkLoaderController.createDigitalElement("0", ElementType.Switch, null);
                        NetworkLoaderController.createDigitalElement("1", ElementType.Switch, null);
                        NetworkLoaderController.createDigitalElement("2", ElementType.ANDGate, null);
                        NetworkLoaderController.createDigitalElement("3", ElementType.Led, null);
                        NetworkLoaderController.createConnection(0, 2);
                        NetworkLoaderController.createConnection(1, 2);
                        NetworkLoaderController.createConnection(2, 3);
                       
                        break;
                    case 1:
                        System.out.println("Szimulacio leptetese");
                        System.out.println("--------------------");
                        
                        NetworkLoaderController.createDigitalElement("0", ElementType.Generator, "01");
                        NetworkLoaderController.createDigitalElement("1", ElementType.Switch, null);
                        NetworkLoaderController.createDigitalElement("2", ElementType.ORGate, null);
                        NetworkLoaderController.createDigitalElement("3", ElementType.Led, null);
                        NetworkLoaderController.createConnection(0, 2);
                        NetworkLoaderController.createConnection(1, 2);
                        NetworkLoaderController.createConnection(2, 3);

                        SimulationController.stepSimulation();
                        
                        break;
                    case 2:
                        System.out.println("Szimulacio resetelese");
                        System.out.println("---------------------");

                        NetworkLoaderController.createDigitalElement("0", ElementType.Generator, "01");
                        NetworkLoaderController.createDigitalElement("1", ElementType.Switch, null);
                        NetworkLoaderController.createDigitalElement("2", ElementType.ORGate, null);
                        NetworkLoaderController.createDigitalElement("3", ElementType.Led, null);
                        NetworkLoaderController.createConnection(0, 2);
                        NetworkLoaderController.createConnection(1, 2);
                        NetworkLoaderController.createConnection(2, 3);

                        SimulationController.resetSimulation();

                        break;
                     case 3:
                        System.out.println("Kapcsolo atkapcsolasa");
                        System.out.println("---------------------");

                        NetworkLoaderController.createDigitalElement("0", ElementType.Switch, null);
                        NetworkLoaderController.createDigitalElement("1", ElementType.Led, null);
                        NetworkLoaderController.createConnection(0, 1);

                        SimulationController.getSwitch(0).stepState();

                        break;
                    case 4:
                        System.out.println("Visszacsatolas");
                        System.out.println("--------------");

                        NetworkLoaderController.createDigitalElement("0", ElementType.Switch, null);
                        NetworkLoaderController.createDigitalElement("1", ElementType.ORGate, null);
                        NetworkLoaderController.createConnection(0, 1);
                        NetworkLoaderController.createConnection(1, 1);

                        SimulationController.stepSimulation();
                        break;
            }

        } catch (Exception e){
            System.out.println(e.getMessage());
            Logger.PrintCallStack(); 
        }
        finally{
            System.out.print("Press Enter to exit...");
            Scanner s = new Scanner(System.in);
            s.nextLine();
        }        
    }
}
